#include <SDL/SDL.h>
#include "game.h"
#include "event.h"
#include "error_mens.h"
#include "treat.h"

/**
 * \file game.c
 * Implementacao dos metodos de game
 */


static int create_world(Game *g)
{



}

static int create_menu(Game *g)
{

}

int create_game(Game *g)
{
    Uint32 i = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; 

    /* Alloca principal estrutura do jogo */
    g = (Game*) malloc (sizeof(Game));
    if(g == NULL) {
        P_ERROR("Erro na alocacao de Game\n");
        exit(-1);
    }

    /* Inicializa o jogo */
    if(SDL_Init(i) < 0) {
        P_ERROR("Erro na inicializacao do sistema SDL\n");
        exit(-1);
    }

    /* Inicializa video */
    g->height = 600;
    g->width = 800;
    SDL_WM_SetCaption("MCZSB", "MCZSB");
    // g->screen = SDL_SetVideoMode(g->width, g->height, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN);
    g->screen = SDL_SetVideoMode(g->width, g->height, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN);
    if(g->screen == NULL) {
        P_ERROR("Erro na inicilizacao do video\n");
        exit(-1);
    }

    return 0;
}

int destroy_game(Game *g)
{

}

int render_game(Game *g)
{


    return 0;
}

int game_main_loop(Game *g)
{
    SDL_Event ev;
    while(1) {
        treat(RENDER_GAME, g, render_game(g));
        treat(EVENT_PROCESS, g, event_process(g, &ev));
    }
}
 
int quit_game(Game *g)
{
    SDL_Quit();
    if(g) free(g);
    exit(0);
}

